#pragma once
#include "WebGUIDoc.h"

// CGraphPane


#define DRAW_BUFF_LEN 100
// this structure holds a circular buffer for the CPU load values for each node
struct NODE_DRAW
{
	NODE_DRAW()
	{
		clr = RGB( 256.0*rand()/RAND_MAX , 256.0*rand()/RAND_MAX, 256.0*rand()/RAND_MAX) ;
		nStart=0;
		for (int n=0;n<DRAW_BUFF_LEN;n++)
		{
			afCPU[n] = -100 ;
		}
	}

	NODE_DRAW &operator=( NODE_DRAW &nd)   // overloading operator = to be used in CArray
	{
		strNodeIP = nd.strNodeIP ;
		nStart = nd.nStart ;
		memcpy(afCPU,nd.afCPU,sizeof(float)*DRAW_BUFF_LEN) ;
		return *this;
	}


	COLORREF clr ;  // the color of the plot for this node
	CString strNodeIP ;  // IP address of the node
	int nStart ; // used internally to know the start point of each circular buffer
	
	float afCPU[DRAW_BUFF_LEN]; // buffer for cpu usage values
	
};


class CGraphPane : public CDockablePane
{
	DECLARE_DYNAMIC(CGraphPane)

public:
	CGraphPane();
	virtual ~CGraphPane();

	afx_msg void OnPaint();
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

protected:
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnDestroy();


	void UpdateList ( CArray <SERVER_NODE,SERVER_NODE> &aNodes ) ;   // add new values to the cpu buffers of each node
	
	CArray <NODE_DRAW,NODE_DRAW> m_aNodes ;  // maintain information for each node
	
	void DrawBK(CDC *pDC);   // Draw Plot back ground
	void DrawPlots(CDC *pDC); // draw plot for all the nodes
	CPoint ToDrawCoordinate(CRect r, float fX,float fY) ; // used internally to convert real world coordinate to draw coordinates

	int m_nDataIndex ; // index for current location in circular buffer
};


